#ifndef GENERICPLUGIN_H
#define GENERICPLUGIN_H

#include "../WingHexExplorer/WingHexExplorer/plugin/iwingplugin.h"
#include "elfhelper.h"
#include <QTreeWidget>

struct Analysis {
  qint64 offset;
  qint64 length;
};

Q_DECLARE_METATYPE(Analysis)

class WingElfPlugin : public IWingPlugin {
  Q_OBJECT
#if QT_VERSION >= 0x050000
  Q_PLUGIN_METADATA(IID IWINGPLUGIN_INTERFACE_IID FILE "WingElfParser.json")
#endif // QT_VERSION >= 0x050000

  Q_INTERFACES(IWingPlugin)

public:
  WingElfPlugin(QObject *parent = nullptr);

  int sdkVersion() override;
  bool init(QList<WingPluginInfo> loadedplugin) override;
  ~WingElfPlugin() override;
  void unload() override;
  QMenu *registerMenu() override;
  QToolButton *registerToolButton() override;
  void
  registerDockWidget(QHash<QDockWidget *, Qt::DockWidgetArea> &rdw) override;
  const QString pluginName() override;
  const QString pluginAuthor() override;
  uint pluginVersion() override;
  const QString signature() override;
  const QString pluginComment() override;
  void plugin2MessagePipe(WingPluginMessage type, QList<QVariant> msg) override;
  HookIndex getHookSubscribe() override;

private:
  QMenu *menu;
  QDockWidget *dw;
  QTreeWidget *tw;
  QToolButton *tbtn;
  QString filename;
  QTranslator translator;

private:
  bool parse();
  bool parse32();
  bool parse64();

  void analyse();
  void applySection();
  void applySymbol();
  void on_setting();
};

#endif // GENERICPLUGIN_H
